package com.topnav.mc.uitls;

import com.js.lib.cache.SysCache;
import com.js.lib.utils.JsonUtil;
import com.topnav.mc.admin.entity.SystemConfig;
import com.topnav.mc.common.Constant;
import com.topnav.mc.common.SysConfigKeyConstant;

import java.util.HashMap;
import java.util.Map;

public class MapUtil {
    /** 中心经纬度 */
    public static Map<String,Double> getCenterPoint(){
        Map<String,Double> result = new HashMap<String,Double>();
        result.put("longitude",114.236262);
        result.put("latitude",22.677236);
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_CENTER_POSITION))!=null){
            SystemConfig sc = (SystemConfig)obj;//JsonUtil.fromJson(obj.toString(),SystemConfig.class);
            String[] lonlats = sc.getSysValue().split(",");
            result.put("longitude",Double.valueOf(lonlats[0]));
            result.put("latitude",Double.valueOf(lonlats[1]));
        };
        return result;
    }

    /** 地图级别 */
    public static Map<String,Integer> getZoomLevel(){
        Map<String,Integer> result = new HashMap<String,Integer>();
        result.put("minZoom",1);
        result.put("maxZoom",20);
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_LEVEL))!=null){
            SystemConfig sc = (SystemConfig)obj;
            //SystemConfig sc = JsonUtil.fromJson(obj.toString(),SystemConfig.class);
            String[] level = sc.getSysValue().split(",");
            result.put("minZoom",Integer.valueOf(level[0]));
            result.put("maxZoom",Integer.valueOf(level[1]));
        };
        return result;
    }
    /** 在线离线地图*/
    public static String getMode(){
        String result = "ONLINE";
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_MODE))!=null){
            SystemConfig sc = (SystemConfig)obj;
            //SystemConfig sc = JsonUtil.fromJson(obj.toString(),SystemConfig.class);
            result = sc.getSysValue();
        };
        return result;
    }

    /** 坐标系*/
    public static String getCoord(){
        String result = "ONLINE";
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_COORD_INFO))!=null){
            SystemConfig sc = (SystemConfig)obj;
            //SystemConfig sc = JsonUtil.fromJson(obj.toString(),SystemConfig.class);
            result = sc.getSysValue();
        };
        return result;
    }

    /**
     * 地图名称
     * @return
     */
    public static String getName(){
        String result = "GaoDe";
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_NAME))!=null){
            SystemConfig sc = (SystemConfig)obj;
            //SystemConfig sc = JsonUtil.fromJson(obj.toString(),SystemConfig.class);
            result = sc.getSysValue();
        };
        return result;
    }

    public static String getSubName(){
        String result = "GaoDeSL";
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_SUB_NAME))!=null){
            SystemConfig sc = (SystemConfig)obj;
            result = sc.getSysValue();
        };
        return result;
    }

    public static Integer getDefaultZoom(){
        Integer result = 14;
        Object obj = null;
        if ((obj= SysCache.getInstance().hget(Constant.CACHE_KEY_SYSTEMCONFIG, SysConfigKeyConstant.MAP_DEFAULT_ZOM))!=null){
            SystemConfig sc = (SystemConfig)obj;
            result = Integer.parseInt(sc.getSysValue());
        };
        return result;
    }
}
